package p3_entities;

import java.io.Serializable;
import javax.persistence.*;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import com.sun.xml.bind.CycleRecoverable;

import java.util.List;


/**
 * The persistent class for the messageboard database table.
 * 
 */
@Entity
@Table(name="messageboard")

@NamedQueries({

@NamedQuery(name="getUserMessageBoard", 
		query="SELECT x FROM Messageboard x WHERE x.userprofile.userId=:userId AND x.type=?1")

})

public class Messageboard implements Serializable, CycleRecoverable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="Id", unique=true, nullable=false)
	private int id;

	//bi-directional many-to-one association to Userprofile
    @ManyToOne
	@JoinColumn(name="UserId", nullable=false, updatable=false)
	private Userprofile userprofile;

    @Column(name="Public", nullable=false)
	private Integer type=0;
    
	//bi-directional many-to-one association to Usermessage
	@OneToMany(mappedBy="userboardId")
	@LazyCollection(LazyCollectionOption.FALSE)
	private List<Usermessage> usermessages;

    public Messageboard() {
    }

	public Messageboard(int id_) {
		this.id = id_;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	public Userprofile getUserprofile() {
		return this.userprofile;
	}

	public void setUserprofile(Userprofile userprofile) {
		this.userprofile = userprofile;
	}
	
	public List<Usermessage> getUsermessages() {
		return this.usermessages;
	}

	public void setUsermessages(List<Usermessage> usermessages) {
		this.usermessages = usermessages;
	}

	@Override
	public Object onCycleDetected(Context arg0) {
		Messageboard obj = new Messageboard(this.id);
		return obj;
	}
	
}